home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 422_02 / dosutil / cset.c < prev    next >
C/C++ Source or Header  |  1994-03-20  |  2KB  |  102 lines

  1. /*
  2.  * This is a handy little program to display the IBM PC character set.
  3.  *
  4.  * If HOTKEYS are specified on the command line, CSET will install
  5.  * itself as a TSR (Ram-Resident) program, which can be invoked at
  6.  * any time by pressing the HOTKEYS. Available HOTKEYS are:
  7.  *        L - Left SHIFT
  8.  *        R - Right SHIFT
  9.  *        A - ALT
  10.  *        C - CONTROL
  11.  *        S - SysRq (Caution: some systems may not like this one)
  12.  *
  13.  *        eg: CSET LR    (Install with LEFT+RIGHT SHIFT for hotkeys)
  14.  *
  15.  * To exit the character set display, press the ESCAPE key.
  16.  *
  17.  * Copyright 1990-1994 Dave Dunfield
  18.  * All rights reserved.
  19.  *
  20.  * Permission granted for personal (non-commercial) use only.
  21.  *
  22.  * Compile command: cc cset -fop
  23.  */
  24. #include <stdio.h>
  25. #include <video.h>
  26. #include <tsr.h>
  27.  
  28. char video_save_area[4006];
  29.  
  30. /*
  31.  * Display the IBM PC Character set
  32.  */
  33. charset()
  34. {
  35.     int i;
  36.  
  37.     save_video(video_save_area);
  38.     vopen();
  39.     vcursor_off();
  40.     V_ATTR = REVERSE;
  41.     vmsg(29,  0, " IBM PC CHARACTER SET ");
  42.     vmsg(29, 21, " Press ESCAPE to exit ");
  43.     V_ATTR = NORMAL;
  44.     for(i=0; i < 256; ++i) {
  45.         vgotoxy((i/16)*5, i%16+3);
  46.         hexout(i / 16);
  47.         hexout(i & 15);
  48.         vputc('=');
  49.         vputc(i | 0xff00); }
  50.     while(vgetc() != 0x1B);
  51.     restore_video(video_save_area);
  52. }
  53.  
  54. /*
  55.  * Display a number
  56.  */
  57. hexout(value)
  58.     int value;
  59. {
  60.     vputc(value <= 9 ? value + '0' : value + '7');
  61. }
  62.  
  63. /*
  64.  * Output message at X and Y coordinates
  65.  */
  66. vmsg(x, y, string)
  67.     int x, y;
  68.     char *string;
  69. {
  70.     vgotoxy(x, y);
  71.     while(*string)
  72.         vputc(*string++);
  73. }
  74.  
  75. /*
  76.  * Main program, either TSR or execute main tty program menu
  77.  */
  78. main(argc, argv)
  79.     int argc;
  80.     int *argv[];
  81. {
  82.     int hot_keys;
  83.     char *ptr;
  84.  
  85. /* If RAM-resident, print startup message & TSR */
  86.     if(argc > 1) {
  87.         fputs("POP-UP Character set\n\nCopyright 1990-1994 Dave Dunfield\nAll rights reserved.", stderr);
  88.         hot_keys = 0;
  89.         ptr = argv[1];
  90.         while(*ptr) switch(toupper(*ptr++)) {
  91.             case 'A' : hot_keys |= ALT;        break;
  92.             case 'C' : hot_keys |= CONTROL;    break;
  93.             case 'L' : hot_keys |= L_SHIFT;    break;
  94.             case 'R' : hot_keys |= R_SHIFT; break;
  95.             case 'S' : hot_keys |= SYS_REQ;    break;
  96.             default: abort("\n\nInvalid HOTKEY"); }
  97.         tsr(&charset, hot_keys, 500); }
  98.  
  99. /* Not RAM-resident, execute the program */
  100.     charset();
  101. }
  102.